let app = getApp();
import {
  rechargeDatalist
} from '../../utils/data'
const {
  submitWithdraw
} = require('../../api/user-center-api')

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    walletInfo:{
      type: Object,
      value: null,
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    rechageDataList: rechargeDatalist,
    amount: 0,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    /**
     * 显示对话框
     */
    showModal() {
      // 显示遮罩层
      var animation = wx.createAnimation({
        duration: 200,
        timingFunction: "linear",
        delay: 0
      })
      this.animation = animation
      animation.translateY(300).step()
      this.setData({
        animationData: animation.export(),
        showModalStatus: true
      })
      setTimeout(function () {
        animation.translateY(0).step()
        this.setData({
          animationData: animation.export()
        })
      }.bind(this), 200)
    },
    /**
     * 隐藏对话框
     */
    hideModal() {
      // 隐藏遮罩层
      let animation = wx.createAnimation({
        duration: 200,
        timingFunction: "linear",
        delay: 0
      })
      this.animation = animation
      animation.translateY(300).step()
      this.setData({
        animationData: animation.export(),
      })
      setTimeout(function () {
        animation.translateY(0).step()
        this.setData({
          animationData: animation.export(),
          showModalStatus: false
        })
      }.bind(this), 200)
    },
    /**
     * 
     * @param {输入提现金额} e 
     */
    onGetCashNum(e){
      this.setData({
        amount:e.detail.value
      })
    },
    onGetCashEvent(){
      let _this = this;
      let params = {
        amount: _this.data.amount/10,
      }
      console.log()
      
      if(params.amount > _this.data.walletInfo.amount) {
        wx.showToast({
          title: '您最多提现的元宝超量了',
          icon: 'none',
          duration: 1500,
        })
        return
      }
      if(walletInfo.bankCard == ''){
        wx.showToast({
          title: '请先绑定银行卡号',
          icon:'none'
        })
        return
      }
      submitWithdraw(params).then(res => {
        wx.showToast({
          title: '提现成功',
          icon: 'none',
          duration: 2000
        })
        wx.navigateBack({
          delta: 1,
        })
      })
    },

  }
})